package com.bankcomm.util;

import android.graphics.Bitmap;

import com.google.zxing.LuminanceSource;

/**
 * BitmapZxingResouce.java
 * 
 * Zxing解析时需要传入LuminanceSource资源才会得到Reuslt结果，这里继承LuminanceSource
 * 并重载其方法
 * 
 * @author cheng.l 2013-5-10 下午12:33:25
 */
public class BitmapZxingResouce extends LuminanceSource {
	private byte[] bitmapPixels;

	public BitmapZxingResouce(Bitmap bitmap) {
		super(bitmap.getWidth(), bitmap.getHeight());

		//图片生成的像素数组
		int[] data = new int[bitmap.getWidth() * bitmap.getHeight()];
		this.bitmapPixels = new byte[bitmap.getWidth() * bitmap.getHeight()];
		bitmap.getPixels(data, 0, getWidth(), 0, 0, getWidth(),
				getHeight());
		
		//将int数组转换为byte数组
		for(int i=0;i< data.length;i++){
			this.bitmapPixels[i] = (byte)data[i];
		}
	}

	@Override
	public byte[] getMatrix() {
		// TODO Auto-generated method stub
		return bitmapPixels;
	}

	@Override
	public byte[] getRow(int y, byte[] row) {
		// TODO Auto-generated method stub
		System.arraycopy(bitmapPixels, y*getWidth(), row, 0, getHeight());
		return row;
	}
}
